package ink.lovejinhu.leetcode;

import ink.lovejinhu.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jinhu
 * created 2021-08-09 14:17
 */
public class Solution_0783 {
    public int minDiffInBST(TreeNode root) {
        this.dfs(root);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < res.size() - 1; i++) {
            int temp = res.get(i + 1) - res.get(i);
            if (temp < min) min = temp;
        }
        return min;
    }

    List<Integer> res = new ArrayList<>();

    public void dfs(TreeNode root) {
        if (root == null) return;
        dfs(root.left);
        res.add(root.val);
        dfs(root.right);
    }
}
